package com.hzy.servlet;

import com.hzy.service.FruitService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Package: servlet
 * @ClassName: DeleteServlet
 * @Author: 862982795
 * @CreateTime: 2021/06/07 9:46
 * @Description:
 */
@WebServlet("/DeleteServlet")
public class DeleteServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        FruitService service = new FruitService();
        int fruitId = Integer.parseInt(req.getParameter("fruitId"));
        System.out.println("fruitId=" + fruitId);

        int i = service.delete(fruitId);
        resp.getWriter().println(i);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
